// mmo_game_server/communication/gossip_client.go
package communication

import (
    "log"

    "github.com/hashicorp/serf/serf"
)

// GossipClient 创建Gossip客户端
func GossipClient() (*serf.Serf, error) {
    config := serf.DefaultConfig()
    s, err := serf.Create(config)
    if err != nil {
        log.Printf("Failed to create Serf instance: %v", err)
        return nil, err
    }
    return s, nil
}

// JoinCluster 加入Gossip集群
func JoinCluster(s *serf.Serf, addresses []string) (int, error) {
    num, err := s.Join(addresses, true)
    if err != nil {
        log.Printf("Failed to join Serf cluster: %v", err)
        return 0, err
    }
    return num, nil
}